home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr49 / vesa18.zip / VESA_WD.C < prev    next >
C/C++ Source or Header  |  1995-01-28  |  4KB  |  112 lines

  1. /* VESA package for emx/gcc --- Copyright (c) 1993 by Johannes Martin */
  2. /* vesa_wd.c                --- Copyright (c) 1994 by David Begley    */
  3. #include <string.h>
  4. #include <sys/hw.h>
  5.  
  6. #define INCL_VIO
  7. #define INCL_DOSPROCESS
  8.  
  9. #include <os2emx.h>
  10. #include <os2thunk.h>
  11.  
  12. #include "vgaports.h"
  13. #include "vesa.h"
  14. #include "vesadll.h"
  15. #include "common.h"
  16.  
  17. #define PR0A 0x9
  18. #define PR1  0xb
  19.  
  20. static VESAWORD _Modes[] = { 0x003, 0x012, 0x013, 0x101, 0x102, 0x103,
  21.                              0x104, 0x105, 0xFFFF };
  22.  
  23. static struct _ModeInfo _ModeInfos[] =
  24.     { { 0x1, { 0x0f, 0x7, 0x0, 64, 64, 0x0, 0x0,
  25.                OS2VesaSetWindow, OS2VesaGetWindow, 160,
  26.                640, 400, 8, 16, 1, 4, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 } },
  27.       { 0x3, { 0x1f, 0x7, 0x0, 64, 64, 0x0, 0x0,
  28.                OS2VesaSetWindow, OS2VesaGetWindow, 80,
  29.                640, 480, 8, 16, 1, 4, 1, 3, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 } },
  30.       { 0x3, { 0x1f, 0x7, 0x0, 64, 64, 0x0, 0x0,
  31.                OS2VesaSetWindow, OS2VesaGetWindow, 320,
  32.                320, 200, 8,  8, 1, 8, 1, 4, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 } },
  33.       { 0xb, { 0x1b, 0x7, 0x0, 64, 64, 0x0, 0x0,
  34.                OS2VesaSetWindow, OS2VesaGetWindow, 640,
  35.                640, 480, 8, 16, 1, 8, 1, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } },
  36.       { 0xb, { 0x1b, 0x7, 0x0, 64, 64, 0x0, 0x0,
  37.                OS2VesaSetWindow, OS2VesaGetWindow, 100,
  38.                800, 600, 8, 16, 4, 4, 1, 3, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 } },
  39.       { 0xb, { 0x1b, 0x7, 0x0, 64, 64, 0x0, 0x0,
  40.                OS2VesaSetWindow, OS2VesaGetWindow, 800,
  41.                800, 600, 8, 16, 1, 8, 1, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } },
  42.       { 0xb, { 0x1b, 0x7, 0x0, 64, 64, 0x0, 0x0,
  43.                OS2VesaSetWindow, OS2VesaGetWindow, 128,
  44.                1024, 768, 8, 16, 4, 4, 1, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } },
  45.       { 0xb, { 0x1b, 0x7, 0x0, 64, 64, 0x0, 0x0,
  46.                OS2VesaSetWindow, OS2VesaGetWindow, 1024,
  47.                1024, 768, 8, 16, 1, 8, 1, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }
  48.     };
  49.  
  50. VESAWORD *Modes             = _Modes;
  51. struct _ModeInfo *ModeInfos = _ModeInfos;
  52.  
  53. VESABOOL Initialize(void)
  54. {
  55.   _portaccess(CRT_I, CRT_D);
  56.   _portaccess(GRA_I, GRA_D);
  57.   return(TRUE);
  58. }
  59.  
  60. VOID ClearUp(void)
  61. {
  62. }
  63.  
  64. VOID *GetPhysBuf(void)
  65. {
  66.   VIOMODEINFO ModeInfo;
  67.   VIOPHYSBUF  PhysBuf;
  68.  
  69.   ModeInfo.cb  = sizeof(ModeInfo);
  70.   VioGetMode(&ModeInfo, 0);
  71.   PhysBuf.pBuf = (PBYTE) ModeInfo.buf_addr;
  72.   PhysBuf.cb   = 0x10000;
  73.   if (VioGetPhysBuf(&PhysBuf, 0) != 0)
  74.     return(NULL);
  75.   else
  76.     return(MAKEP(PhysBuf.asel[0], 0));
  77. }
  78.  
  79. VESABOOL SetMode(VESAWORD mode)
  80. {
  81.   VIOMODEINFO ModeInfo;
  82.  
  83.   ModeInfo.cb     = 12;
  84.   ModeInfo.fbType = ModeInfos[mode].fbtype;
  85.   ModeInfo.color  = ModeInfos[mode].Vesa.NumberOfBitsPerPixel;
  86.   ModeInfo.col    = ModeInfos[mode].Vesa.Width  / ModeInfos[mode].Vesa.CharacterWidth;
  87.   ModeInfo.row    = ModeInfos[mode].Vesa.Height / ModeInfos[mode].Vesa.CharacterHeight;
  88.   ModeInfo.hres   = ModeInfos[mode].Vesa.Width;
  89.   ModeInfo.vres   = ModeInfos[mode].Vesa.Height;
  90.   return(VioSetMode(&ModeInfo, 0) == 0);
  91. }
  92.  
  93. void SetSpecial(VESAWORD mode)
  94. {
  95.   _outp8(GRA_I, PR1);
  96.   _outp8(GRA_D, _inp8(GRA_D) & 0xF7);
  97. }
  98.  
  99. VESABOOL OS2VesaSetWindow(VESACHAR Window, VESAWORD Address)
  100. {
  101.   _outp8(GRA_I, PR0A);
  102.   _outp8(GRA_D, Address << 4);
  103.   return(TRUE);
  104. }
  105.  
  106. VESABOOL OS2VesaGetWindow(VESACHAR Window, PVESAWORD Address)
  107. {
  108.   _outp8(GRA_I, PR0A);
  109.   *Address = _inp8(GRA_D) >> 4;
  110.   return(TRUE);
  111. }
  112.